<template>
  <div>
    <y-header></y-header>
    <div class="person_body clearfix">
      <y-side :type="'dyn'"></y-side>
      <div class="person_content">
        <ul class="person_title clearfix">
          <li>提问与答疑</li>
        </ul>
        <div class="person_info ">
            <div>             
              <select v-model="obj.courseId" @change="getanswerDoubtList"  style="height: 34px;" >
                                <option value="">全部</option>
                                <option v-for="course in courseList" :checked="obj.courseId == course.id" :key="course.id" :value="course.id" v-html="course.courseName"></option>
              </select>
            </div>

          <table class="table ">
            <thead>
              <tr>
                    <th>序号</th>
                    <th>提问者</th>
                    <th>问题</th>
                    <th>时间</th>
                    <th>操作</th>  
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item, index) in listForQuestion" :key="item.id">
                    <td>{{index + 1}}</td>
                    <td class="name">{{item.studentName}}</td>     
                    <td class="name">{{item.title}}</td>    
                     <td class="name">{{item.gmtCreate}}</td>                                      
                    <td class="operate">
                      <router-link tag="a" target="_blank" :to="'/view/detail?themeId=' +item.id+ '&title='+ (item.title) + '&userType=1'" class="text_link">
                        展开查看并回复
                    </router-link>
                     
                    </td>
                  </tr>         
                  <tr>                              
                </tr> 
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <y-footer></y-footer>
  </div>
</template>
<script>
import YHeader from '~/components/common/Header'
import YFooter from '~/components/common/Footer'
import YSide from '~/components/account/Side'
import YUpload from '~/components/account/Upload'
import {courseOtherFileList,saveCourseOtherFile,courseListByUserNo,delCourseOtherFileList,answerDoubtList,answerDoubtViewDetail,answerDoubtSaveReply} from '../../../api/account/courseOtherFile'
export default {
  data () {
    return {
      load: false,
      tab: 1,
      num: 1,
      list: [],
      solidBtn: false,
      courseList: [],
      listForQuestion:[], 
      obj: {
        courseId: '',
        title:[]     
      },
      fileUrl: ''
    }
  },
  computed: {
    isUp () {
      if (this.fileUrl) {
        return false
      } else {
        return true
      }
    }
  },
  methods: {
    // 获取上传附件
    getUrl (file) {
  
      this.fileUrl = file.url || ''
      this.obj.fileName = file.name || ''
      this.obj.fileUrl = file.url || ''
    },
  
    
   
  
    addPraxis () {
      if (!this.obj.courseId) {
        this.$msgBox({
          content: '请选择所属课程',
          isShowCancelBtn: false
        })
        return
      }
      // if (!this.fileUrl) {
      //   this.$msgBox({
      //     content: '请上传文件',
      //     isShowCancelBtn: false
      //   })
      //   return
      // }
      this.solidBtn = true;
      this.obj.type = 2;
    
      saveCourseOtherFile(this.obj).then(res => {
        res = res.data;
        this.solidBtn = false;
        if (res.code === 200) {
          this.list.push(res.data);
          this.num = this.list.length + 1;
          this.fileUrl = '';
          this.obj.title ='';
        } else {
          if (res.code >= 300 && res.code < 400) {
            this.$msgBox({
              content: res.msg,
              isShowCancelBtn: false
            }).then(() => {
              this.$store.dispatch('REDIRECT_LOGIN', result.code)
            }).catch(() => {
              this.$store.dispatch('REDIRECT_LOGIN', result.code)
            })
          } else {
            this.$msgBox({
              content: res.msg,
              isShowCancelBtn: false
            }).catch(() => {})
          }
        }
        // console.log(res)
      }).catch(() => {
        this.solidBtn = false;
        this.$msgBox({
          content: '',
          isShowCancelBtn: false
        })
      })
    },

    // clicktab: function (int) {
    //       this.tab = int;
    //       this.pageCurrent = 1;
    //       this.getCourseOtherFileList();
    //     },

    getanswerDoubtList () {  
      answerDoubtList({
           courseId: this.obj.courseId,      
      }).then(res => {
        let result = res.data
        if (result.code === 200) {
           console.log(result.data.list);
          this.listForQuestion = result.data.list;       
          this.notdata = false;
          this.pageObj = result.data;
        } else if (result.code > 300 && result.code <400) {
          this.$msgBox({
            content: '登录超时，请重新登录',
            isShowCancelBtn: false
          }).then(() => {
            this.$store.dispatch('REDIRECT_LOGIN', result.code)
          }).catch(() => {
            this.$store.dispatch('REDIRECT_LOGIN', result.code)
          })
        } else {
          this.notdata = true;
          this.pageObj.totalPage = 0;
        }
        cons
      }).catch(msg => {
        // this.$msgBox({
        //   content: '加载数据失败，请稍后刷新再试！！',
        //   isShowCancelBtn: false
        // })
      })
    },

    getCourseList () {
      
      courseListByUserNo({
           userNo: this.$store.state.userInfo.userNo
      }).then(res => {
        let result = res.data
        if (result.code === 200 && result.data.list.length > 0) {
          this.courseList = result.data.list;
          this.notdata = false;
          this.pageObj = result.data;
        } else if (result.code > 300 && result.code <400) {
          this.$msgBox({
            content: '登录超时，请重新登录',
            isShowCancelBtn: false
          }).then(() => {
            this.$store.dispatch('REDIRECT_LOGIN', result.code)
          }).catch(() => {
            this.$store.dispatch('REDIRECT_LOGIN', result.code)
          })
        } else {
          this.notdata = true;
          this.pageObj.totalPage = 0;
        }
      }).catch(msg => {
        // this.$msgBox({
        //   content: '加载数据失败，请稍后刷新再试！！',
        //   isShowCancelBtn: false
        // })
      })
    }
  },
  



  mounted() {    
    this.getCourseList();
    this.getanswerDoubtList();
  },
  components: {
    YHeader,
    YFooter,
    YUpload,
    YSide
  }
}
</script>
<style lang="scss" rel="stylesheet/scss">
@import '~/assets/css/account.scss';
  .person_body {
    width: 1200px;
    margin: 30px auto 0;
    min-height: 1000px;
    .upload_com {
      .solid_btn {
        display: inline-block;
        height: 25px;
        line-height: 22px;
        background: #fff;
        border-color: #ddd;
        color: #999;
        outline: none;
        &:hover {
          color: #D51423;
          border-color: #D51423;
        }
      }
    }
  }
  .person_content {
    width: 1012px;
    float: right;
    background: #fff;
    border-radius: 6px;
  }
  .person_title {
    border-bottom: 1px solid rgb(242, 242, 242);
    li {
      color: #D51423;
      float: left;
      line-height: 60px;
      padding: 0 30px;
      border-bottom: 2px solid #D51423;
      font-size: 14px;
    }
  }
  .person_info {
    padding-bottom: 40px;
  }
  .name{
    .form_input{
      margin: 10px 0;
      height: 34px;
      border: 1px solid #e7e7e7;
      width: 278px;
      text-indent: 1em;
    }
  }
  .cont_btn {
    width: 280px;
    display: block;
    margin:20px auto 0;
  }
  .table td.name {
    text-align: center;
  }
  .table th {
    line-height: 36px;
    color: #333;
    background-color: #ffffff;
}
</style>
